
import { defineStore } from 'pinia';

export const useAuthStore = defineStore('auth', {
  state: () => ({
    isLogin: false, // 登录状态
    userInfo: {}   // 用户信息
  }),
  actions: {
    setLogin(status, user_info) {
      this.isLogin = status;
      this.userInfo = user_info;
      // 如果需要同步到本地存储，可以在这里添加
      uni.setStorageSync("isLogin", status);
      uni.setStorageSync("user_info", user_info);
    },
    initialize() {
      // 初始化时从本地存储读取登录状态
      const storedLoginStatus = uni.getStorageSync("isLogin");
      if (storedLoginStatus !== undefined) {
        this.isLogin = storedLoginStatus;
      }
      const storeUserInfo = uni.getStorageSync("user_info");
      if (storedLoginStatus !== undefined) {
        this.userInfo = storeUserInfo;
      }
    },
  },
});